/* JavaLog - pkg tracker 
* 
* Copyright (C) 2009 Allyson Lima, Diego Pedro, Victor Freire
* 
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software 
* Foundation, either version 3 of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along with this 
* program. If not, see <http://www.gnu.org/licenses/>.
*/

package br.edu.ufcg.ccc.javalog;
import br.edu.ufcg.ccc.javalog.exceptions.PackageException;

/**
* A OneDay Package
* @author Allyson Lima, Diego Pedro, Victor Freire
* @version 08/11/09
*/
public class PackageOneDay extends Package {
	
	/**
	 * Static final attribute for type package
	 */
	private final static String type = "ONEDAY";
	
	/**
	 * Constructor default
	 * 
	 * @param senderAddress
	 *            Address of the sender
	 * @param recipientAddress
	 *            Address of the recipient
	 * @param sourceStore
	 *            Source Store
	 * @param destinationStore
	 *            Destination Store
	 * @throws PackageException
	 *             Invalid arguments
	 */
	public PackageOneDay(Address senderAddress,
			Address recipientAddress, Store sourceStore,
			Store destinationStore) throws PackageException {
		super(senderAddress, recipientAddress, sourceStore,
				destinationStore);
	}	
	
	/**
	 * Returns the type of the package
	 * 
	 * @return the type of the package
	 */
	@Override
	public String getType() {
		return type;
	}
	
	@Override
	public void move() throws PackageException {
		if(getCurrentStore() == getDestinationStore()) throw new PackageException("move() should not be called! the package is already at the destination");
		
		if(getDestinationStore().hasAirport()) {
			// send directly to destination, it has an airport
			setCurrentStore(getDestinationStore());
		}
		else {
			// send to nearest Store with airport indicated by the destination store
			Store nearestAirportStore = getDestinationStore().getNearestAirport();
			if(nearestAirportStore == getCurrentStore()) {
				// the package has gone all the way it can by air, time to go by land
				Store nextStore = getSourceStore().getNextStoreInShortestPath(getDestinationStore());
				setCurrentStore(nextStore);
			}
		}
		
		// TODO Update package tracking report
	}
}
